var express = require('express');
var router = express.Router();
const Mongoose = require('mongoose');
const { ObjectId } = Mongoose.Types;
var messageModel = require('../tool/model/message.js');
router.get('/', (req, res, next)=> {
        res.render('message', {
          id: req.cookies['id']
        })
});
router.get('/message', (req, res, next)=> {
  messageModel.find({},function(err,docs){
      if(err){
        return
      }
      res.send({
        data:docs
      })
  })

});
router.post('/messagedel', (req, res, next)=> {
  let paras = req.body
  messageModel.remove({'_id':  new ObjectId(paras.id)},function(err,docs){
      if(err){
        return
      }
      res.send({
        type:'success',
        message:'已删除该留言'
      })
  })

});
module.exports = router;